﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace FormTest {
    public partial class DateFormat : UserControl {

        public string Value { get; set; }

        public DateFormat() {
            InitializeComponent();
        }

        private void DateFormat_Load(object sender, EventArgs e) {
            this.cbFormat.SelectedIndex = this.cbSeperator.SelectedIndex = 0;
        }

        private void btnSubmit_Click(object sender, EventArgs e) {
            if (this.cbFormat.SelectedIndex == -1 ||
                this.cbSeperator.SelectedIndex == -1) {
                this.cbFormat.SelectedIndex = this.cbSeperator.SelectedIndex = 1;
            }

            string[,] dateFormats = { { "yyyy", "MM", "dd" }, { "MM", "dd", "yyyy" }, { "dd", "MM", "yyyy" } };
            string[] datetimeFormats = { "HH", "mm" };
            char[] seperators = { '-', '.', '/' };

            int formatIndex = this.cbFormat.SelectedIndex;
            int seperatorIndex = this.cbSeperator.SelectedIndex;
            bool supportTimeFlag = this.cbSupportTime.Checked;

            string result = string.Empty;
            for (int i = 0; i < 3; i++) {
                result += dateFormats[formatIndex, i] + seperators[seperatorIndex];
            }
            if (supportTimeFlag) {
                result = result.TrimEnd(seperators[seperatorIndex]) + " ";
                foreach (string s in datetimeFormats) {
                    result += s + ":";
                }
                result=result.TrimEnd(':');
            }            
        }
    }
}
